<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* 
        slice()
           有三个或多个参数时，替换元素
        语法：
           数组名.splice(start[,num,ele ...]);
           star :第一个值为插入元素的位置
           num： 第二个值为被替换元素的个数
           ele...：被替换的元素
        */
       let arr = [1,2,3,4,5,6,];
       let arr2 = arr.splice(2, 3, "张飞", "牛肉", "手机", "鼠标");
       //表示2后面的三个元素替换为  （"张飞", "牛肉", "手机", "鼠标"），其他元素正常输出
       console.log(arr, arr2);

console.log('------------2---------------');
       //2.如果第二个值为0，则不替换，直接插入6,7,8;
       let arr3 = [1,2,3,4,5,6,];
       let arr4 = arr.splice(2, 0, "张飞", "牛肉", "手机", "鼠标","李白");
       console.log(arr3, arr4);
    </script>
</body>
</html>